package utils

import (
	"github.com/mozillazg/go-pinyin"
	"strings"
	"unicode"
)

func FirstLetterToUpper(s string) string {
	if len(s) == 0 {
		return s
	}
	r := []rune(s)
	r[0] = unicode.ToUpper(r[0])
	return string(r)
}

func ConvertHanZi2Pinyin(chineseWords string) string {
	pinyinArgs := pinyin.NewArgs()
	pinyinArgs.Style = pinyin.Normal //pinyin.FIRST_LETTER
	pinyinSlice := pinyin.Pinyin(chineseWords, pinyinArgs)
	pinyinArr := []string{}
	for _, item := range pinyinSlice {
		sTmp := strings.Join(item, "-")
		sTmp = FirstLetterToUpper(sTmp)
		pinyinArr = append(pinyinArr, sTmp)
	}
	return strings.Join(pinyinArr, "")
}
